package com.ruoyi.auth.plugin.api;


import com.stylefeng.sso.plugin.constants.SsoConstants;
import com.stylefeng.sso.plugin.properties.SsoProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 单点登录token校验API  客户端需要做退出，服务端做鉴权
 *
 * @author fengshuonan
 * @date 2018-02-04 11:56
 */

/**
 *
 */
@Controller
public class SsoApiTemp {
    private Logger log = LoggerFactory.getLogger(this.getClass());


    @Autowired
    private SsoProperties ssoProperties;


    @RequestMapping("logout2")
    public String logout2(HttpServletRequest request, HttpServletResponse response)
    {

        log.info("我要开始走logout2了");
        HttpSession session = request.getSession();
        String redirectUrl = ssoProperties.getServerUrl() + "/logout"
                + "?" + SsoConstants.REDIRECT_PARAM_NAME + "=http://localhost:80"
//                + HttpUtil.encodeUrl(HttpUtil.getRequestContextPath(request))
                + "&" + SsoConstants.TOKEN_PARAM_NAME +"="+ session.getAttribute(SsoConstants.SESSION_LOGIN_FLAG);


        log.info("这块开始打印 logout2 redirectUrl");
        log.info(redirectUrl);
        try {
            response.sendRedirect(redirectUrl);
        } catch (IOException e) {
            log.error("退出跳转到服务器地址出错!", e);
        }
        return null;

    }


}
